package com.summer.main;

public class ClosureTest {
		
	public static void main(String[] args) {
		ClosureRef.ref.setLst(() -> {
			System.out.println("lst 执行了");
		});
		ClosureRef.ref.init();
		ClosureRefA.ref.show();
		
		ClosureRef.ref.setLst(null);
		ClosureRefA.ref.show();
		
	}
	
	
	public static class ClosureRef {
		
		public static ClosureRef ref = new ClosureRef();
		
		
		public ClosureLst lst;

		public void setLst(ClosureLst lst) {
			this.lst = lst;
		}
		
		public void init() {
			ClosureRefA.ref.setLst(new ClosureLst() {

				@Override
				public void show() {
					// TODO Auto-generated method stub
					if(lst!=null) {
					lst.show();
					} else {
						System.out.println("lst 被释放了");
					}
				}
				
			});
		}
		
	}
	
	public static class ClosureRefA {
		public static ClosureRefA ref = new ClosureRefA();
		public ClosureLst lst;
		
		public void setLst(ClosureLst lst) {
			this.lst = lst;
		}
		
		public void show() {
			if(lst != null) {
				lst.show();
			}
		}
		
	}
	
	public interface ClosureLst {
		public void show();
	}
}
